#ifndef __I2C_H__
#define __I2C_H__
#include "gd32f10x.h"

/* i2c1相关宏 */
#define I2C1_SCL_PORT       GPIOB
#define I2C1_SCL_PIN        GPIO_PIN_3

#define I2C1_SDA_PORT       GPIOB
#define I2C1_SDA_PIN        GPIO_PIN_4

#define I2C1_SCL_HIGH()     gpio_bit_set(I2C1_SCL_PORT, I2C1_SCL_PIN)
#define I2C1_SCL_LOW()      gpio_bit_reset(I2C1_SCL_PORT, I2C1_SCL_PIN)

#define I2C1_SDA_HIGH()     gpio_bit_set(I2C1_SDA_PORT, I2C1_SDA_PIN)
#define I2C1_SDA_LOW()      gpio_bit_reset(I2C1_SDA_PORT, I2C1_SDA_PIN)

#define I2C1_SDA_READ()     gpio_input_bit_get(I2C1_SDA_PORT, I2C1_SDA_PIN)

/* i2c2相关宏 */
#define I2C2_SCL_PORT       GPIOB
#define I2C2_SCL_PIN        GPIO_PIN_8

#define I2C2_SDA_PORT       GPIOB
#define I2C2_SDA_PIN        GPIO_PIN_9

#define I2C2_SCL_HIGH()     gpio_bit_reset(I2C2_SCL_PORT, I2C2_SCL_PIN)     //硬件上作了反向
#define I2C2_SCL_LOW()      gpio_bit_set(I2C2_SCL_PORT, I2C2_SCL_PIN)

#define I2C2_SDA_HIGH()     gpio_bit_reset(I2C2_SDA_PORT, I2C2_SDA_PIN)
#define I2C2_SDA_LOW()      gpio_bit_set(I2C2_SDA_PORT, I2C2_SDA_PIN)

/* i2c1对外接口函数 */
void i2c1_start(void);
void i2c1_send_byte(uint8_t byte);
uint8_t i2c1_read_byte(void);
void i2c1_ack(void);
void i2c1_nack(void);
void i2c1_wait_ack(void);
void i2c1_stop(void);
/* i2c2对外接口函数 */
void i2c2_start(void);
void i2c2_send_byte(uint8_t byte);
void i2c2_ack(void);
void i2c2_nack(void);
void i2c2_stop(void);

void i2c_init(void);
#endif
